'''
装饰器的使用
运用场景： 权限检验，日记记录，接口时长统计
'''


import inspect
import functools


def api(func):

    @functools.wraps(func)  # 保持原有方法名称
    def wrapper(name, *args, **kwargs):
        params = inspect.getcallargs(func, *args, **kwargs)
        print(params.get('age'))
        print('wrapper: ')
        print(name)
        print(args)
        print(kwargs)
        func(name, *args, **kwargs)
        print('wrapper.__name__: ', wrapper.__name__)
    return wrapper


@api
def hello(name, *args, **kwargs):
    print('hello: ', name)


hello('dsc', 10, 1, province='sichuan', age=20)

# dsc
# (10, 1)
# {'province': 'sichuan', 'age': 20}
# hello:  dsc